package config;

import java.math.BigDecimal;
import java.util.*;

/**
 * @author admin
 * 商品
 */
public interface Commodity {

    HashMap<String, Price> COMMODITY = new HashMap<>();

    /**
     * 初始化
     */
    static void init(){
        COMMODITY.put("白菜",new Price(new BigDecimal("2.1"),new BigDecimal("0.5")));
        COMMODITY.put("土豆",new Price(new BigDecimal("2.5"),new BigDecimal("0.5")));
        COMMODITY.put("青菜",new Price(new BigDecimal("0.8"),new BigDecimal("0.2")));
        COMMODITY.put("车厘子",new Price(new BigDecimal("48.5"),new BigDecimal("10")));
        COMMODITY.put("核桃",new Price(new BigDecimal("61"),new BigDecimal("13")));
        COMMODITY.put("白银",new Price(new BigDecimal("108.5"),new BigDecimal("20")));
        COMMODITY.put("黄金",new Price(new BigDecimal("380.5"),new BigDecimal("50")));
        randPrice();
    }

    /**
     * 商品价格重随
     */
    static void randPrice(){
        for (Map.Entry<String, Price> priceEntry : COMMODITY.entrySet()) {
            priceEntry.setValue(priceEntry.getValue().rand());
        }
    }

    /**
     * 在切换城市的时候更换商品,每个城市只有五种商品,完全随机
     * 随机移除两个商品
     */
    static void randCommodity(){
        COMMODITY.clear();
        init();
        ArrayList<String> keys = new ArrayList<>(COMMODITY.keySet());
        Collections.shuffle(keys);
        String key01 = keys.get(0);
        String key02 = keys.get(0);
        COMMODITY.remove(key01);
        COMMODITY.remove(key02);
    }
}
